package com.dddd.blog.blogsp.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dddd.blog.blogsp.entity.Author;
import com.dddd.blog.blogsp.entity.BlogAuthor;
import org.apache.ibatis.annotations.*;

import java.text.MessageFormat;
import java.util.List;
import java.util.Map;

/**
 *
 * @author 喵星球的大橘
 */
@Mapper
public interface BlogAuthorMapper extends BaseMapper<Author> {


    /**
     * 获取作者昵称列表
     * @return
     */
    @Select("select distinct(author) from pms_post")
    List<String> getAuthorNameList();


    /**
     * 返回作者的Map属性集合
     * @return
     */
    @Select("select distinct username, id, uuid, home_link, create_time from pms_author")
    @MapKey("id")
    @ResultType(Map.class)
    List<Map<String,Object>> getAuthorList();




    /**
     * 批量插入博客用户
     * @param list
     * @return sql语句
     */

    /** @InsertProvider(type = BlogAuthorMapperProvider.class,method = "insertAll")*/

    /**
     *
     * @param list
     * @return
     */
    @Insert("<script>" +
            "insert into pms_user " + "(username,icon,nickname,email,gender,birthday,create_time," +
            "status,uuid,blog_link) values "+
            "<foreach collection=\"list\" index=\"index\" item=\"item\" separator=\",\" open=\"(\" close=\")\"> " +
                "#{item.username},#{item.icon},#{item.nickName},#{item.email},#{item.gender},#{item.birthday}," +
                "#{item.createTime},#{item.status},#{item.uuid},#{item.blogLink}"+
            "</foreach> "+
            "</script>")

    String addAllBlogAuthor(List<BlogAuthor> list);

}




class BlogAuthorMapperProvider{
    /**
     * @return 批量插入sql语句
     */
    public String insertAll(Map map){
        StringBuilder builder = new StringBuilder();
        List<BlogAuthor> list = (List<BlogAuthor>) map.get("list");

        builder.append("INSERT INTO pms_user ");
        builder.append("(username,icon,nickName,email,gender,birthday,crete_time,status,uuid,blog_link) ");
        builder.append("VALUES ");
        MessageFormat mf = new MessageFormat("");
        return null;
    }
}